package fun.gladlee.smartmsg;

import android.app.Activity;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class SmartMsgActivity extends Activity implements View.OnClickListener
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        findViewById(R.id.bt_add_event).setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.bt_add_event:
                String subject = ((EditText) findViewById(R.id.et_subject)).getText().toString();
                String dateStr=((EditText) findViewById(R.id.et_date)).getText().toString();
                long date = Long.parseLong(dateStr);
                ContentValues v = new ContentValues();
                v.put(EventsContract.Events.COL_SUBJECT,subject);
                v.put(EventsContract.Events.COL_DATE,date);
                try {
                    getContentResolver().insert(
                            new Uri.Builder().authority(EventsContract.AUTHORITY)
                                    .scheme(ContentResolver.SCHEME_CONTENT)
                                    .appendPath(EventsContract.Events.PATH)
                                    .build(),
                            v
                    );
                } catch (Exception e) {
                    e.printStackTrace();
                }
                break;
        }
    }
}
